package com.ruoyi.web.controller.train;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.framework.web.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TrainingBaseDept;
import com.ruoyi.system.service.ITrainingBaseDeptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮转科室信息Controller
 * 
 * @author dp
 * @date 2023-11-27
 */
@Api(tags = {"轮转科室信息管理"})
@RestController
@RequestMapping("/train/dept")
public class TrainingBaseDeptController extends BaseController
{
    @Autowired
    private ITrainingBaseDeptService trainingBaseDeptService;
    @Autowired
    TokenService tokenService;

    /**
     * 查询轮转科室信息列表
     */
    @ApiOperation(value = "轮转科室信息列表", notes = "查询轮转科室信息列表详情", tags = {"轮转科室信息管理"})
    //@PreAuthorize("@ss.hasPermi('train:dept:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainingBaseDept trainingBaseDept)
    {
        startPage();
        List<TrainingBaseDept> list = trainingBaseDeptService.selectTrainingBaseDeptList(trainingBaseDept);
        return getDataTable(list);
    }

    /**
     * 导出轮转科室信息列表
     */
    @ApiOperation(value = "轮转科室信息列表导出", notes = "导出轮转科室信息列表", tags = {"轮转科室信息管理"})
    //@PreAuthorize("@ss.hasPermi('train:dept:export')")
    @Log(title = "轮转科室信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainingBaseDept trainingBaseDept)
    {
        List<TrainingBaseDept> list = trainingBaseDeptService.selectTrainingBaseDeptList(trainingBaseDept);
        ExcelUtil<TrainingBaseDept> util = new ExcelUtil<TrainingBaseDept>(TrainingBaseDept.class);
        util.exportExcel(response, list, "轮转科室信息数据");
    }

    /**
     * 获取轮转科室信息详细信息
     */
    @ApiOperation(value = "轮转科室信息详细信息", notes = "获取轮转科室信息详细信息", tags = {"轮转科室信息管理"})
    //@PreAuthorize("@ss.hasPermi('train:dept:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return success(trainingBaseDeptService.selectTrainingBaseDeptByDeptId(deptId));
    }

    /**
     * 新增轮转科室信息
     */
    @ApiOperation(value = "新增轮转科室信息", notes = "新增轮转科室信息", tags = {"轮转科室信息管理"})
    //@PreAuthorize("@ss.hasPermi('train:dept:add')")
    @Log(title = "轮转科室信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(HttpServletRequest request, @RequestBody TrainingBaseDept trainingBaseDept)
    {
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        trainingBaseDeptService.completeData(trainingBaseDept, userId, 1);
        return toAjax(trainingBaseDeptService.insertTrainingBaseDept(trainingBaseDept));
    }

    /**
     * 修改轮转科室信息
     */
    @ApiOperation(value = "修改轮转科室信息", notes = "修改轮转科室信息", tags = {"轮转科室信息管理"})
    //@PreAuthorize("@ss.hasPermi('train:dept:edit')")
    @Log(title = "轮转科室信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(HttpServletRequest request, @RequestBody TrainingBaseDept trainingBaseDept)
    {
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        trainingBaseDeptService.completeData(trainingBaseDept, userId, 2);
        return toAjax(trainingBaseDeptService.updateTrainingBaseDept(trainingBaseDept));
    }

    /**
     * 删除轮转科室信息
     */
    @ApiOperation(value = "删除轮转科室信息", notes = "删除轮转科室信息", tags = {"轮转科室信息管理"})
    //@PreAuthorize("@ss.hasPermi('train:dept:remove')")
    @Log(title = "轮转科室信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(trainingBaseDeptService.deleteTrainingBaseDeptByDeptIds(deptIds));
    }
}
